package com.nine.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.nine.IService.CustomerService;
import com.nine.entity.Customer;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sun.net.httpserver.Authenticator.Failure;

public class LoginAction extends ActionSupport {//implements SessionAware,ServletRequestAware{
	String customerId;
	String password;
	
	public Customer customer;
	CustomerService customerService; 
	
	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public CustomerService getCustomerService() {
		return customerService;
	}

	public void setCustomerService(CustomerService customerService) {
		this.customerService = customerService;
	}

	@Override
	public String execute() throws Exception  {
		// TODO Auto-generated method stub

		customer.setPoint(0);
		Timestamp registrationTime = new Timestamp(System.currentTimeMillis());
		customer.setRegistrationTime(registrationTime);
		if(customerService.registerCustomer(customer)){
			ActionContext.getContext().put("user", customer);
			//this.session.put("USER_NAME",u.getCustomerId());
			return 	SUCCESS;
			}
		else
			return ERROR;		
	}
	
	public String execute2() throws Exception {
		// TODO Auto-generated method stub
//		Customer u = new Customer();
//		u.setCustomerId("104029062@qq.com");
//		//u.setCustomerId(name);
//		u.setPassword(password);
//		u.setPoint(0);
		
//		List<Customer> a = new ArrayList<Customer>();//;
//		Customer u = new Customer();
//		u.setCustomerId("104029062@qq.com");
//		Timestamp registrationTime = new Timestamp(2011, 6, 15, 20, 20, 20, 10);
//		u.setRegistrationTime(registrationTime);
//		a.add(u);
//		u = new Customer();
//		u.setCustomerId("104029061@qq.com");
//		Timestamp registrationTime2 = new Timestamp(2011, 6, 15, 20, 20, 20, 10);
//		u.setRegistrationTime(registrationTime2);
//		a.add(u);		
		ActionContext.getContext().put("pagelist", customerService.getAllCustomer());
		//this.request.setAttribute("pagelist",a);
		//if(customerService.register(user))
			return 	SUCCESS;
		//else
			//return ERROR;		
	}
	
//	 private Map session;   
//	  
//	    public void setSession(Map session) {   
//	  
//	       this.session = session;   
//	  
//	  
//	    }
//	    private HttpServletRequest request; 
//
//		public void setServletRequest(HttpServletRequest arg0) {
//			// TODO Auto-generated method stub
//			this.request = request; 
//		} 

}
